import asyncio


class FutureExample:
    def __init__(self, data):
        self.data = data
        self.future = asyncio.Future()

    async def set_date_future(self):
        print("Starting to set data...")

        if not self.future.done():
            print("future设置中...")
            await asyncio.sleep(2)  # Simulate a delay
            data = [{"i": i, "value": f"value_{i}"} for i in range(10)]
            self.future.set_result(data)
            print("future数据设置完成.")

    async def get_data_future(self):
        data = await self.future
        print("Data received:", data)


async def future_example():
    example = FutureExample(None)
    await asyncio.gather(example.set_date_future(), example.get_data_future())


asyncio.run(future_example())
